﻿///
/// Test script file NetworkTest.fsx.
/// Test for Network.fs
///

#load "Network.fs"

open PathFinder.Network

(* Commutativity test *)
printfn "--------------------------------------------------------------"
printfn "Beginning commutativity test for norm on two NetworkNode(s)..."
printfn "--------------------------------------------------------------"
(* Test body *)
let myNode = NetworkNode ("MyNode") (* A node in origin *)
let anotherNode = NetworkNode ("AnotherNode", 12.0, 3.0) (* A noe in some certain coordinates *)
let dist = Norm (myNode, anotherNode) (* Calculating distance *)
let dist2 = Norm (anotherNode, myNode) (* Calculating distance *)
let ok = (dist = dist2) (* Checking commutativity *)
(* Test result *)
printfn "Distace A->B is %f and distance B->A is %f ==> TEST RES = %b" dist dist2 ok

(* Neighbourhood test *)
printfn ""
printfn "-------------------------------"
printfn "Beginning neighbourhood test..."
printfn "-------------------------------"
(* Test body *)
printfn "Defining nodes and setting neighbours as A->(A1, A2, A3, AB->(B1, B2))"
let nodeA = new NetworkNode ("Node A")
let nodeA1 = new NetworkNode ("Node A1")
let nodeA2 = new NetworkNode ("Node A2")
let nodeA3 = new NetworkNode ("Node A3")
let nodeAB = new NetworkNode ("Node AB")
let nodeB1 = new NetworkNode ("Node B1")
let nodeB2 = new NetworkNode ("Node B2")
nodeA.AddNeighbour (nodeA1, 10.0)
nodeA.AddNeighbour (nodeA2, 9.0)
nodeA.AddNeighbour (nodeA3, 11.0)
nodeA.AddNeighbour (nodeAB, 10.0)
nodeAB.AddNeighbour (nodeB1, 12.0)
nodeAB.AddNeighbour (nodeB2, 3.0)
printfn "Node -> %s" (nodeA.ToString ())
printfn "Node -> %s" (nodeA1.ToString ())
printfn "Node -> %s" (nodeA2.ToString ())
printfn "Node -> %s" (nodeA3.ToString ())
printfn "Node -> %s" (nodeAB.ToString ())
printfn "Node -> %s" (nodeB1.ToString ())
printfn "Node -> %s" (nodeB2.ToString ())
(* Test result *)
printfn "Testing references for A..."
for i = 0 to (nodeA.Grade - 1) do
    printfn "Node A child -> %s" (nodeA.[i].ToString ())
printfn "Adding a neighbour to A2 using previous reference"
nodeA2.AddNeighbour (nodeB2, 20.0)
printfn "Rescanning A neighbours after change"
for i = 0 to (nodeA.Grade - 1) do
    printfn "Node A child -> %s" (nodeA.[i].ToString ())

(* Indexer test *)
printfn "-------------------------"
printfn "Beginning indexer test..."
printfn "-------------------------"
(* Test result *)
printfn "Node A is: %s" (nodeA.ToString ())
printfn "Verifying cyclic integer indexer"
for i = 0 to (2 * nodeA.Grade) - 1 do
    printfn "Node A child -> %s" (nodeA.[i].ToString ())
printfn "Verifying string indexer"
printfn "Node A child 'Node A1' -> %s" (nodeA.["Node A1"].ToString ())
printfn "Node A child 'Node A2' -> %s" (nodeA.["Node A2"].ToString ())
printfn "Node A child 'Node A3' -> %s" (nodeA.["Node A3"].ToString ())
printfn "Node A child 'Node AB' -> %s" (nodeA.["Node AB"].ToString ())
if not (nodeA.["Non existing"] = None) then
    printfn "Node A child 'Non existing' -> %s" (nodeA.["Non existing"].ToString ())
else
    printfn "Node A child 'Non existing' -> None!"
